package com.kobe.algorithm.niue.calculator;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author ：caopengfei
 * @date ：2021/5/9
 */
public class Main {

    public static void main(String[] args) {

        String numArr = "0123456789";

        String level1 = "+-";

        String level2 = "{[(*/";
        //遇到这些符号，出栈运算
        String level3 = ")]}";

        Scanner scanner =  new Scanner(System.in);
        String input = scanner.nextLine();

        Stack<String> stack = new Stack<>();
        int level = 0;
        for (int i = 0; i < input.length() ; i++) {
            String currentStr = input.substring(i,i+1);

            if(i <2){
                stack.add(currentStr);
                continue;
//            level =
            }
            String beforeStr = input.substring(i-1,i);
            //负数
            if(currentStr.equals("-") &&  numArr.contains(beforeStr)){
                stack.add("0");
                stack.add(currentStr);
            }

            String nextStr = input.substring(i+1,i+2);
            if(level3.contains(currentStr) || level1.contains(nextStr)){
                String num2  = stack.pop();
                String type =  stack.pop();
                String num1 =  stack.pop();
                stack.add(cal(num1,type,num2)+"");
            }else{
                stack.add(currentStr);
            }
        }
    }

    private static int cal(String numStr, String type,String num2Str){
        int num = Integer.parseInt(numStr);
        int num2 = Integer.parseInt(num2Str);
        if(type.equals("+")){
            return num +num2;
        }else if(type.equals("-")){
            return num  - num2;
        }else if(type.equals("*")){
            return num  * num2;
        }else if(type.equals("/")){
            return num  / num2;
        }else{
            throw  new RuntimeException("type is error");
        }
    }



}
